package src;

public class Trains extends Thread{
	private int placesLibres;
	private int VITESSE_TRAIN;
	private Gare gare;
	
	private static int CAPACITE_TRAIN = 5;
	private static int ARRET_TRAIN = 10000;

	public Trains (Gare g)
	{
		int v = (int)((Math.random()*250)+50);
		int pl = (int)((Math.random()*CAPACITE_TRAIN));
		this.placesLibres = pl;
		this.VITESSE_TRAIN = v;
		this.gare = g;
	
	}
	
	public int getPlacesLibres()
	{
		return placesLibres;
	}
	
	public void setPlacesLibres(int p)
	{
		this.placesLibres = p;
	}
	
	public void run()
	{
		System.out.println("Je suis un nouveau trains numero " + Thread.currentThread().getName() + ", je vais a la vitesse " + VITESSE_TRAIN + ". J'ai " + placesLibres + " places libres, et maintenant je roule pour arriver en gare");
		try {sleep(10000/VITESSE_TRAIN);} catch(InterruptedException e) {}		
		int numVoie = this.gare.getQuais().arriveeTrain(this);
		System.out.println("Le train " + Thread.currentThread().getName()+ " arrive en gare en voie" + numVoie);
		try {sleep(ARRET_TRAIN);} catch(InterruptedException e) {}
		this.gare.getQuais().departTrain(numVoie);
		System.out.println("Le train " + Thread.currentThread().getName()+ "part de la gare en voie" + numVoie);
	}
	
	
}
